Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 메모 수정/삭제 시, 캘린더에 반영 안되는 것 수정 #130

Merged
merged 7 commits into from
Oct 10, 2023

Conversation

HI-JIN2
Copy link
Member

@HI-JIN2 HI-JIN2 commented Oct 10, 2023

Description

메모 수정/삭제 시, 캘린더에 반영 안되는 것 수정

Main Features

  • Weather 엔티티에서 대표 온도/상태 필드를 삭제하였습니다.
    • 수정이나 삭제 둘 중 하나만 반영하는 문제가 있어서 필드에 저장해놓고 사용하는 것이 아닌, 그때그때 조회를 하는 것이 더 정확하다 판단하였습니다.
  • Weather 엔티티에 대표 온도/상태를 저장하고 갱신하는 기존의 방식에서 다음과 같은 방법으로 변경하였습니다.
    • findFirstByWeatherIdOrderByTemperatureDesc를 통해 해당 날짜의 가장 높은 온도인 메모를 가져와서 ItemDTO에 넣어서 리스트를 반환하는 방식을 채택하였습니다.
    @Transactional(readOnly = true)
    public WeatherMonthlyResponseDto getMonthlyList(int year, int month, CustomUserDetails userDetails) {

        LocalDate startDate = LocalDate.of(year, month, 1);
        LocalDate lastDate = startDate.withDayOfMonth(startDate.lengthOfMonth());

        List<WeatherItemResponseDto> weatherItemResponseDtoList = new ArrayList<>();
        List<Weather> weatherList = weatherRepository.findByMonthAndUser(userDetails.getUser(), startDate, lastDate);

        for(Weather weather : weatherList){

            Memo highestMemo = memoRepository.findFirstByWeatherIdOrderByTemperatureDesc(weather.getId());
            WeatherItemResponseDto weatherItemResponseDto = WeatherItemResponseDto.builder()
                    .weatherId(weather.getId())
                    .date(weather.getDate())
                    .highestStatus(highestMemo.getStatus())
                    .highestTemperature(highestMemo.getTemperature())
                    .build();

            weatherItemResponseDtoList.add(weatherItemResponseDto);
        }


        return new WeatherMonthlyResponseDto(weatherItemResponseDtoList);
    }

Others

  • SecurityConfig에 cors 설정 추가
@Bean
    CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(List.of("*"));
        configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
        configuration.setAllowedHeaders(List.of("*"));
        configuration.setExposedHeaders(List.of("*"));
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }

@HI-JIN2 HI-JIN2 self-assigned this Oct 10, 2023
@HI-JIN2 HI-JIN2 linked an issue Oct 10, 2023 that may be closed by this pull request
3 tasks
@HI-JIN2 HI-JIN2 merged commit 3744176 into main Oct 10, 2023
@HI-JIN2 HI-JIN2 deleted the 129-fix-largest-data-error branch October 10, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fix] largest data error
1 participant